﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.CopsBanditsUI {
    import flash.events.*;
    import Engine.Managers.*;
    import Engine.Interfaces.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Events.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Modules.workers.*;
    import com.greensock.*;
    import flash.filters.*;
    import Modules.bandits.*;
    import Display.*;
    import Display.FactoryUI.*;
    import flash.text.*;
    import Classes.actions.*;
    import Display.aswingui.*;
    import Engine.*;
    import com.zynga.skelly.util.*;
    import Modules.bandits.transactions.*;
    import com.greensock.easing.*;

    public class BanditSlidePick extends SlidePick implements IInputHandler {

        public static const SLIDE_WIDTH:int = 550;
        public static const BUTTON_HEIGHT:int = 22;
        public static const BUTTON_LABEL_HEIGHT:int = 40;
        public static const INFO_PANE_HEIGHT:int = 24;
        public static const SLIDE_Y_OFFSET:int = 10;
        public static const STATE_CLOSED:int = 0;
        public static const STATE_INFO:int = 1;
        public static const STATE_ACCEPT_DECLINE:int = 2;

        protected const PICK_OFFSET:Point;

        protected var m_state:int;
        protected var m_position:Vector3;
        protected var m_listeningToRender:Boolean = false;
        protected var m_slideVisible:Boolean = false;
        protected var m_banditId:int;
        protected var m_outFrames:int = 0;
        protected var m_out:Boolean = false;
        protected var m_followMovement:Boolean = false;
        protected var m_accepted:Boolean = false;
        protected var m_npc:NPC = null;
        protected var m_banditData:BanditData;
        protected var m_floatBox:JPanel;
        protected var m_toolTip:AssetPane;
        protected var m_info:JLabel;
        protected var m_info2:JLabel;
        protected var m_tweenCount:int = 0;
        protected var m_tweenY:Number = 0;

        public function BanditSlidePick(_arg1:NPC, _arg2:BanditData, _arg3:Boolean=false, _arg4:Boolean=false, _arg5:int=0, _arg6:Boolean=false){
            this.PICK_OFFSET = new Point(-30, -70);
            this.m_npc = _arg1;
            this.m_state = STATE_CLOSED;
            this.m_banditData = _arg2;
            this.m_toolTip = ASwingHelper.makeMultilineText(ZLoc.t("Bandits", "ToolTip", {
                banditName:this.m_banditData.name,
                count:this.m_banditData.requiredCops
            }), 500, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 16, EmbeddedArt.whiteTextColor, [new GlowFilter(0, 1, 4, 4, 10, BitmapFilterQuality.LOW)]);
            this.m_toolTip.mouseChildren = false;
            this.m_toolTip.mouseEnabled = false;
            var _local7:String = this.m_banditData.thumbnail;
            _local7 = ((_local7)=="") ? null : Global.getAssetURL(_local7);
            super(_local7, _arg3, _arg4, _arg5, false, SLIDE_WIDTH);
            addEventListener(MouseEvent.MOUSE_DOWN, this.onClick, false, 0, true);
            addEventListener(MouseEvent.MOUSE_OVER, this.onOver, false, 0, true);
            addEventListener(MouseEvent.MOUSE_OUT, this.onOut, false, 0, true);
            addEventListener(MouseEvent.MOUSE_MOVE, this.onMove, false, 0, true);
            InputManager.addHandler(this);
            this.m_followMovement = true;
            this.m_toolTip.x = (((-(this.m_toolTip.width) / 2) + (this.m_mainSprite.width / 2)) + 5);
            this.m_toolTip.y = -((this.m_toolTip.height + 10));
        }
        protected function onClick(_arg1:MouseEvent):void{
            if (Global.ui.mouseEnabled == false){
                return;
            };
            this.onAccept(_arg1);
        }
        protected function onMove(_arg1:MouseEvent):void{
        }
        protected function onOver(_arg1:MouseEvent):void{
            if (Global.ui.mouseEnabled == false){
                return;
            };
            if (this.m_accepted){
                return;
            };
            if (!contains(this.m_toolTip)){
                addChild(this.m_toolTip);
            };
            this.m_out = false;
            this.m_outFrames = 0;
        }
        protected function onOut(_arg1:MouseEvent):void{
            this.m_out = true;
            this.m_outFrames = 0;
            if (contains(this.m_toolTip)){
                removeChild(this.m_toolTip);
            };
        }
        public function showSlidePane():void{
            if (this.m_slideVisible){
                return;
            };
            this.m_state = STATE_ACCEPT_DECLINE;
            m_sliderActive = true;
            this.buildAndShowInnerPane();
            this.m_slideVisible = true;
            this.m_followMovement = false;
            if (this.m_npc){
                this.m_npc.actionQueue.removeAllStates();
            };
        }
        public function getPickSprite():Sprite{
            return (this.m_mainSprite);
        }
        override protected function getPickBackground():Class{
            return (EmbeddedArt.trainUIPick);
        }
        override protected function getInnerBackground():Class{
            return (EmbeddedArt.friendReplaySlide);
        }
        override protected function initInner():void{
            super.initInner();
            switch (this.m_state){
                case STATE_INFO:
                    this.initInfo();
                    break;
                case STATE_ACCEPT_DECLINE:
                    this.initToaster();
                    break;
            };
        }
        public function isTweening():Boolean{
            return (!((m_tween == null)));
        }
        protected function onUpdateTween(_arg1:Object):void{
            var _local2:Vector3 = Vector3.lerp(_arg1.startPos, _arg1.endPos, _arg1.alpha);
            this.m_position = _local2;
        }
        protected function onCompleteTween():void{
            m_tween.kill();
            m_tween = null;
        }
        public function tweenToPos(_arg1:Vector3, _arg2:Number=1.5):void{
            var _local3:Object;
            if (m_tween){
                m_tween.complete(true);
                m_tween.kill();
                m_tween = null;
            };
            _local3 = {
                startPos:this.m_position,
                endPos:_arg1,
                alpha:0
            };
            m_tween = new TimelineLite({
                onUpdate:this.onUpdateTween,
                onUpdateParams:[_local3],
                onComplete:this.onCompleteTween
            });
            m_tween.appendMultiple([new Z_TweenLite(_local3, _arg2, {alpha:1})]);
            this.startListen();
            m_tween.gotoAndPlay(0);
        }
        override public function setPosition(_arg1:Number, _arg2:Number):void{
            if (!this.m_followMovement){
                return;
            };
            this.m_position = new Vector3((_arg1 + 3), (_arg2 + 3));
            this.startListen();
        }
        protected function renderListener(_arg1:Event):void{
            var _local2:Point;
            if (this.m_out){
                this.m_outFrames++;
                if ((((((this.m_outFrames == 45)) && (this.m_slideVisible))) && ((this.m_state == STATE_ACCEPT_DECLINE)))){
                    this.closeInnerPane();
                };
            };
            if (this.m_position){
                _local2 = IsoMath.tilePosToPixelPos(this.m_position.x, this.m_position.y);
                _local2 = IsoMath.viewportToStage(_local2);
                this.x = (_local2.x + this.PICK_OFFSET.x);
                this.y = ((_local2.y + this.PICK_OFFSET.y) + this.m_tweenY);
            };
        }
        protected function startListen():void{
            if (((!(this.m_listeningToRender)) && (!((stage == null))))){
                stage.addEventListener(Event.RENDER, this.renderListener, false, 0, true);
                this.m_listeningToRender = true;
            };
        }
        override public function kill(_arg1:Function=null):void{
            super.kill(_arg1);
            if (this.m_listeningToRender){
                Global.stage.removeEventListener(Event.RENDER, this.renderListener);
                this.m_listeningToRender = false;
            };
            removeEventListener(MouseEvent.MOUSE_DOWN, this.onClick, false);
            removeEventListener(MouseEvent.MOUSE_OVER, this.onOver, false);
            removeEventListener(MouseEvent.MOUSE_OUT, this.onOut, false);
            removeEventListener(MouseEvent.MOUSE_MOVE, this.onMove, false);
            InputManager.removeHandler(this);
        }
        override public function cleanUp():void{
            super.cleanUp();
            if (this.parent){
                this.parent.removeChild(this);
            };
        }
        protected function initInfo():void{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(AsWingConstants.CENTER);
            _local1.setPreferredWidth(slideWidth);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.CENTER);
            _local2.setPreferredHeight(INFO_PANE_HEIGHT);
            this.m_info = new JLabel(this.m_banditData.name);
            this.m_info.setFont(ASwingHelper.getBoldFont(14));
            _local2.append(this.m_info);
            ASwingHelper.prepare(_local2);
            _local1.append(_local2);
            _local2 = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.LEFT);
            _local2.setPreferredHeight(INFO_PANE_HEIGHT);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel();
            _local3.setPreferredWidth(30);
            ASwingHelper.prepare(_local3);
            _local2.append(_local3);
            this.m_info2 = new JLabel(ZLoc.t("Dialogs", "ClickToRespond"));
            this.m_info2.setFont(ASwingHelper.getBoldFont(14));
            _local2.append(this.m_info2);
            ASwingHelper.prepare(_local2);
            _local1.append(_local2);
            ASwingHelper.prepare(_local1);
            innerAppendAll(_local1);
        }
        protected function initToaster():void{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(AsWingConstants.CENTER);
            ASwingHelper.setEasyBorder(_local1, 0, 20, 0, 10);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.CENTER);
            _local2.setPreferredHeight(BUTTON_LABEL_HEIGHT);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.CENTER, 15);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanel();
            _local4.setHeight(10);
            ASwingHelper.prepare(_local4);
            _local2.append(_local4);
            _local3.alpha = 0;
            m_innerPanel.setBackgroundDecorator(null);
            ASwingHelper.prepare(_local2);
            ASwingHelper.prepare(_local3);
            _local1.appendAll(_local2, _local3);
            ASwingHelper.prepare(_local1);
            innerAppendAll(_local1);
        }
        public function banditClicked():void{
            this.onAccept(null);
        }
        protected function onAccept(_arg1:Event):void{
            var _local2:BanditEscapedDialog;
            BanditUtil.logGameActionStats("active_building", "police", "bandit_npc_click", this.m_banditData);
            if (BanditManager.numUsableCops >= this.m_banditData.requiredCops){
                this.captureBandit();
            } else {
                this.m_npc.hideSlidePick();
                this.m_npc.playActionCallback = null;
                this.m_npc.slidePick = null;
                _local2 = new BanditEscapedDialog(this.m_banditData.id, false, this.buyCaptureBandit);
                UI.displayPopup(_local2);
            };
        }
        protected function captureBandit(_arg1:Boolean=false):void{
            var _local3:CopsNBanditsWorkers;
            var _local4:Array;
            var _local5:Array;
            var _local6:CopData;
            var _local7:int;
            var _local2:ArrestScene = BanditManager.createArrestScene(this.m_banditData, this.m_npc.getPosition(), this.m_npc, _arg1);
            if (_local2){
                this.closeInnerPane();
                this.m_npc.hideSlidePick();
                this.m_accepted = true;
                _local3 = (Global.copsNBanditsWorkerManager.getWorkers("cops") as CopsNBanditsWorkers);
                _local4 = _local3.getMultipleNpcOwners(_local2.m_cops);
                _local5 = [];
                for each (_local6 in _local4) {
                    _local5.push(_local6.getPosition());
                    _local6.setState(CopData.STATE_SLEEPING);
                    _local6.setTimestamp(Math.floor((GlobalEngine.getTimer() / 1000)));
                    _local3.setCopData(_local6);
                };
                BanditManager.numBanditsCaptured++;
                BanditManager.typesBanditsCaptured[this.m_banditData.id] = true;
                _local7 = BanditManager.bandits.indexOf(this.m_banditData.id);
                if (_local7 > -1){
                    BanditManager.bandits.splice(_local7, 1);
                };
                _local7 = BanditManager.banditsSpawned.indexOf(this.m_banditData.id);
                if (_local7 > -1){
                    BanditManager.banditsSpawned.splice(_local7, 1);
                };
                if (_arg1){
                    GameTransactionManager.addTransaction(new TBuyCaptureBandit(this.m_banditData.id, _local5));
                } else {
                    GameTransactionManager.addTransaction(new TCaptureBandit(this.m_banditData.id, _local5));
                };
            };
        }
        protected function buyCaptureBandit(_arg1:GenericPopupEvent):void{
            var cashCost:* = 0;
            var e:* = _arg1;
            var killBandit:* = false;
            if (e.button == GenericDialogView.YES){
                cashCost = Global.gameSettings.getInt("CNBcatchBanditNowCashCost", 5);
                if ((((cashCost > 0)) && ((Global.player.cash >= cashCost)))){
                    this.captureBandit(true);
                    Global.player.cash = (Global.player.cash - cashCost);
                } else {
                    UI.displayPopup(new GetCoinsDialog(ZLoc.t("Dialogs", "ImpulseMarketCash"), "GetCash", GenericDialogView.TYPE_GETCASH, null, true));
                    killBandit = true;
                };
            } else {
                killBandit = true;
            };
            if (killBandit){
                if (this.m_npc){
                    this.closeInnerPane();
                    this.m_npc.clearStates();
                    this.m_npc.animation = "static";
                    this.m_npc.getStateMachine().addActions(new ActionNavigateRandom(this.m_npc).setTimeout(2), new ActionTween(this.m_npc, ActionTween.TO, 1, {alpha:0}), new ActionFn(this.m_npc, Curry.curry(function (_arg1:NPC):void{
                        if (Global.world.citySim.npcManager.isNpcTracked(_arg1)){
                            Global.world.citySim.npcManager.removeWalker(_arg1);
                        } else {
                            _arg1.detach();
                            _arg1.cleanUp();
                        };
                    }, this.m_npc)));
                };
                this.m_npc = null;
            };
        }
        protected function buildAndShowInnerPane():void{
            this.rebuildInner();
            this.showInnerPane();
        }
        public function toggleInnerPane():void{
            if (this.m_slideVisible){
                Z_TweenLite.to(m_innerSprite, 0.5, {
                    x:m_offXPos,
                    onComplete:this.buildAndShowInnerPane
                });
            };
        }
        public function closeInnerPane():void{
            if (this.m_slideVisible){
                this.m_slideVisible = false;
                this.m_followMovement = true;
                Z_TweenLite.to(m_innerSprite, 0.5, {
                    x:m_offXPos,
                    onComplete:this.panelClosed
                });
            };
        }
        public function get slideVisible():Boolean{
            return (this.m_slideVisible);
        }
        protected function panelClosed():void{
        }
        override protected function get innerYOffset():Number{
            return (SLIDE_Y_OFFSET);
        }
        public function tweenBounce():void{
            if (m_tween != null){
                m_tween.complete(false);
                m_tween.kill();
                m_tween = null;
            };
            var _local1:Object = {
                pos:0,
                endPos:-(HEIGHT_OFFSET),
                alpha:0
            };
            m_tween = new TimelineLite({
                onUpdate:this.onUpdateAnim,
                onUpdateParams:[_local1]
            });
            m_tween.appendMultiple([new Z_TweenLite(_local1, 0.5, {
                alpha:1,
                ease:Back.easeOut
            }), new Z_TweenLite(_local1, 0.5, {
                alpha:0,
                ease:Back.easeIn
            })], 0, TweenAlign.SEQUENCE);
            m_tween.gotoAndPlay(0);
        }
        protected function onUpdateAnim(_arg1:Object):void{
            var _local2:Number = (_arg1.endPos * _arg1.alpha);
            this.m_tweenY = _local2;
        }
        public function onMouseDown(_arg1:MouseEvent):Boolean{
            return (false);
        }
        public function onMouseUp(_arg1:MouseEvent):Boolean{
            var _local2:Rectangle;
            if (this.m_slideVisible){
                _local2 = this.getRect(this.parent);
                if (!_local2.contains(_arg1.stageX, _arg1.stageY)){
                    this.closeInnerPane();
                } else {
                    return (true);
                };
            };
            return (false);
        }
        public function onMouseOut(_arg1:MouseEvent):Boolean{
            return (false);
        }
        public function onMouseMove(_arg1:MouseEvent):Boolean{
            return (false);
        }
        public function onMouseDoubleClick(_arg1:MouseEvent):Boolean{
            return (false);
        }
        public function onMouseWheel(_arg1:MouseEvent):Boolean{
            return (false);
        }
        public function onKeyDown(_arg1:KeyboardEvent):Boolean{
            return (false);
        }
        public function onKeyUp(_arg1:KeyboardEvent):Boolean{
            return (false);
        }

    }
}//package Display.CopsBanditsUI 
